package com.yb.xczx.cloud.system.message.listener;

import com.alibaba.fastjson.JSONObject;
import com.rabbitmq.client.Channel;
import com.yb.core.model.message.XczxRabbitMQMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * Copyright (C), 2022-2022, 姚兵
 * Author: 32210
 * Date: 2022/9/16 12:54
 * FileName: DemoListener
 * Description: rabbit
 */

@Component
@Slf4j
public class DemoListener {

    @RabbitListener(queues = {"#{T(com.yb.xczx.cloud.system.constant.RabbitConstant.DemoQueue).DEMO_QUEUE}"})
    public void handle(String content, Message message, Channel channel){
        long deliveryTag = message.getMessageProperties().getDeliveryTag();
        try {
            log.info("receive content={}", content);

            channel.basicAck(deliveryTag,false);
        }catch (Exception e){
            log.info("exception e={}",e);
            try {
                channel.basicReject(deliveryTag,true);
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            }
        }

    }
}
